package com.sd.common.utils;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期格式化工具类
 * @author yexinming
 * @date 2020/4/18 19:26
 */
@Component
public class DateProviderImpl implements DateProvider {
    /**
     * 获取当前时间
     * @return
     * @throws Exception
     */
    @Override
    public Date getCurrentTime() throws Exception{
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.parse(dateFormat.format(new Date()));
    }

    @Override
    public String formatDatetime(Date date) throws Exception {
        SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormatter.format(date);
    }

    @Override
    public Date parseDatetime(String datetime) throws Exception {
        SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormatter.parse(datetime);
    }
}
